﻿@using Microsoft.AspNet.Identity
@model SocialGoal.Web.ViewModels.GroupUpdateListViewModel
@*<script src="../../Scripts/jquery-latest.js" type="text/javascript"></script>*@

    <h5 style="margin-left:15px;">Latest Updates</h5>
@if (Model.GroupUpdates.Count() == 0)
{
    <div class ="alert alert-info"> No updates on this goal</div>
}
<div class="span12 hero-unit" id ="DisplayGroupUpdates" style="margin-left: 0px;padding: 15px;">
    @foreach (var item in Model.GroupUpdates)
    {
        
        
         <div class="well span12" style="margin-left:1px;">

        <div class="span12" id="GroupUpdateStatus@(item.GroupUpdateId)" >           
                <span style="margin-left:13px; font-size:14px;cursor:help;">@item.Updatemsg</span>
              
                @if (item.UserId == User.Identity.GetUserId())
                { 
                    <div class="EditDeleteUpdate span3" style="float:right;">
                        <a style="float:right;" href="JavaScript:void(0);" id="deleteGroupupdate" onclick ="DeleteGroupUpdate('@item.GroupUpdateId')" >
                            <span rel="tooltip" title="Delete Group Update"><i class="icon-trash"></i></span></a>
                        <a style="float:right;" href="JavaScript:void(0);" id ="editGroupupdate" value ="@item.Updatemsg"onclick ="EditGroupUpdate('@item.GroupUpdateId')">
                            <span rel="tooltip" title="Edit Group Update"><i class=" icon-edit"></i></span></a>
                       
                    </div>
                }        
             <div class="span12" style="font-size:11px;">On @item.UpdateDate.ToString("dd MMM yyyy - hh:mm tt")</div> 
        </div>
         
   
        <div id="supportGroupUpdate@(item.GroupUpdateId)" class ="row-fluid span7" style ="font-size:12px;">
            @if (item.IsSupported == false)
            {
                <a href ="JavaScript:void(0);" id ="supportUpdate@(item.GroupUpdateId)" onclick ="SupportGroupUpdate('@item.GroupUpdateId')" title="Support this update">Support</a> <text> | </text>
            }
            else
            { 
             <a href ="JavaScript:void(0);" id ="unSupportUpdate@(item.GroupUpdateId)" onclick ="UnSupportGroupUpdate('@item.GroupUpdateId')" title="Un Support this update">Unsupport</a> <text> | </text>
            }

            @{
            var supportCount = Html.Action("NoOfSupports", new { id = item.GroupUpdateId });
            var commentCount = Html.Action("NoOfComments", new { id = item.GroupUpdateId });
             }
              
             @if (supportCount.ToHtmlString() != "0")
             {
                <a data-toggle="modal" href="#groupUpdateSupporters" id ="SupportGroupCount@(item.GroupUpdateId)" onclick="SupportersOfGroupUpdate('@item.GroupUpdateId')">@supportCount Supports<i class="icon-thumbs-up"></i></a>  <text> | </text>
             }
             else
             { 
                 <a data-toggle="modal" href="#groupUpdateSupporters" id ="SupportGroupCount@(item.GroupUpdateId)" onclick="SupportersOfGroupUpdate('@item.GroupUpdateId')">0 Supports</a>  <text> | </text>
             }
             @if (commentCount.ToHtmlString() != "0")
             {
                <a href="JavaScript:void(0);" id="commentGroupToggle@(item.GroupUpdateId)" onclick = "CommentExpandInGroupUpdate('@item.GroupUpdateId','@commentCount')" title="Comment this update"> @commentCount Comments<i class="icon-comment"></i> </a>
             }
             else
             {
                 <a href="JavaScript:void(0);" id="commentGroupToggle@(item.GroupUpdateId)"@* onclick = "CommentExpandInGroupUpdate(@item.GroupUpdateId)"*@ title="Comment this update"> 0 Comments</a>
             }        
        </div>
         
        
        <div id="divgroupcommentUpdate@(item.GroupUpdateId)" class="span9 well" style="display:none">
        </div>
        <div class="span12">
            <div class="span8 input-append">
                <input type="text" class ="span8" id="GroupCommentText@(item.GroupUpdateId)" onfocus ="EnableGroupCommentBtn('@item.GroupUpdateId')" onblur ="DisableGroupCommentBtn('@item.GroupUpdateId')" placeholder="Write your comments here.." onkeypress="checkKey(event,@item.GroupUpdateId);"/>
                <button id="postComment@(item.GroupUpdateId)" disabled ="disabled" class="btn" style="margin-bottom:10px;" onclick="updateGroupComment(@item.GroupUpdateId);">Post</button>
            </div>
              @if ((Model.Target != null) && (item.status != null) && (Model.Target != 0) && Model.Metric.Type != "%")
              {
                    <div class="span11 alert alert-info goal-status-message">
                        <strong>Status</strong> :<strong>@item.status @Model.Metric.Type</strong> achieved out of <strong>@Model.Target @Model.Metric.Type</strong>
                     </div>
              }
              else
              {

            <div class="span4" style="float:right;margin-right:0px;padding-left:10px;">
                @if ((Model.Target == null) && (item.status != null))
                {              
                    @:Status: item.status
                    if (Model.Metric != null)
                    {@Model.Metric.Type}
                }
                else if ((Model.Target != null) && (item.status != null) && Model.Metric.Type == "%")
                {   
                    <div class="progress progress-striped active" style="height:25px;width:150px;border:1px solid #B6B4B4;">
                        <div class="bar" style="color:Black;width:@Html.Action("GoalProgress", "Group", new { id = item.GroupUpdateId })%;">
                           @if (item.status < Model.Target)
                           {<span style="float:left;line-height:25px;padding-left:10px;" >@item.status/@Model.Target</span>}
                           else
                           {<span style="float:left;line-height:25px;padding-left:10px;" >Target Achieved</span>}                                                                                               
                        </div>
                    </div>
                }
            </div>
              }
        </div>
        

               
    </div>
     @Html.Hidden("GroupUpdateId" + item.GroupUpdateId, item.GroupUpdateId)
        
        
        
        
        
        
        
      <script type="text/javascript">
          function checkKey(e, id) {
              evt = e || window.event;
              if (evt.keyCode == 13) {
                  updateGroupComment(id);
                  e.preventDefault();
              }

          }

          function EnableGroupCommentBtn(id) {
              $("#postComment" + id).removeAttr("disabled");
          }


          function DisableGroupCommentBtn(id) {
              if ($("#GroupCommentText" + id).val() == "") {
                  $("#postComment" + id).attr("disabled", "disabled");
              }
          }
      </script>
        
        
        
        
        
        
        
        
        
        
        
        
        
        @*<div>
            <div class="row-fluid" id = "GroupUpdateStatus@(item.GroupUpdateId)">
                <div class="span8" id="Groupupdatemsg">@item.Updatemsg
                    @if (((SocialGoal.Web.Core.Models.SocialGoalUser)(User.Identity)).UserId == item.UserId)
                    { 
                        <a href="JavaScript:void(0);" id ="editGroupupdate" value ="@item.Updatemsg"onclick ="EditGroupUpdate('@item.GroupUpdateId')">
                            <span rel="tooltip" title="Edit Group Update"><i class=" icon-edit"></i></span>
                        </a><a href="JavaScript:void(0);" id="deleteGroupupdate" onclick ="DeleteGroupUpdate('@item.GroupUpdateId')" >
                            <span rel="tooltip" title="Delete Group Update"><i class="icon-trash"></i></span>
                        </a>   }
                </div>
                @if ((Model.Target == null) && (item.status == null))
                { 
                    <div id="trgt+@item.GroupUpdateId" class="span4" style="float: right;" >
                    </div>
                }
                else if ((Model.Target == null) && (item.status != null))
                {
                    <div id="trgt+@item.GroupUpdateId" class="span4" style="float: right;" >
                        Status: @item.status
                        @if (Model.Metric != null)
                        {@Model.Metric.Type}
                    </div>
                }
                else if ((Model.Target != null) && (item.status != null))
                {
               
                    <div id="trgt+@item.GroupUpdateId" class="span4" style="float:right;" >
                        <div class="progress progress-striped active" style="width: 150px; border: 1px solid #B6B4B4;">
                            <div class="bar" style="color:Black;width:@Html.Action("GoalProgress", "Group", new { id = item.GroupUpdateId })%;">
                                <span>@item.status/@Model.Target</span>
                            </div>
                        </div>
                    </div>
                }
                <br />
            </div>
            <div class="row-fluid span5">
                <div id="supportGroupUpdate@(item.GroupUpdateId)" class ="span3" style ="float:left">
                    @if (item.IsSupported == false)
                    {
                        <a href ="JavaScript:void(0);" id ="supportUpdate@(item.GroupUpdateId)" onclick ="SupportGroupUpdate('@item.GroupUpdateId')">
                            Support</a>
                    }
                    else
                    { 
                        <a href ="JavaScript:void(0);" id ="unSupportUpdate@(item.GroupUpdateId)" onclick ="UnSupportGroupUpdate('@item.GroupUpdateId')" >
                            UnSupport</a>
                    }
                </div>
                <div class="span4">
                    <a data-toggle="modal" href="#groupUpdateSupporters" id ="SupportGroupCount@(item.GroupUpdateId)" onclick="SupportersOfGroupUpdate('@item.GroupUpdateId')">
                        @Html.Action("NoOfSupports", new { id = item.GroupUpdateId }) Supports<i class="icon-thumbs-up"></i></a>
                </div>
                <div class="span4" style="float: right">
                    <a href="JavaScript:void(0);">
                        <label id="commentGroupToggle@(item.GroupUpdateId)" onclick = "CommentExpandInGroupUpdate(@item.GroupUpdateId)">
                            @Html.Action("NoOfComments", new { id = item.GroupUpdateId })
                            Comments<i class="icon-comment"></i></label>
                    </a>
                </div>
            </div>
            <div id="divgroupcommentUpdate@(item.GroupUpdateId)" class="span12" style="display:none">
            </div>
            <input type="text" class ="span9" id="GroupCommentText@(item.GroupUpdateId)" placeholder="Enter your comments here......."  size="30" onfocus="value=''"  onkeypress="checkKey(event,@item.GroupUpdateId);"/>
            <button id="postComment@(item.GroupUpdateId)" class="btn btn-primary" style="margin-bottom:10px;" onclick="updateGroupComment(@item.GroupUpdateId);">
                Comment</button>
            @Html.Hidden("GroupUpdateId" + item.GroupUpdateId, item.GroupUpdateId)
            <hr />
        </div>*@
    }
</div>
